//
//  PTCoreManager+LifeService.m
//  PlanTech
//
//  Created by ruifeng song on 2018/7/16.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "PTCoreManager+LifeService.h"
#import "PTCoreObject+LifeService.h"
#import "SINAHttpRequestUtils.h"

@implementation PTCoreManager (LifeService)

-(NSString *)getServiceTypeName:(PTLifeServiceType)type
{
    NSString * str =nil;
    switch (type) {
        case PTLifeService_ExpressType:
            str =@"代取快递";
            break;
        case PTLifeService_PrintType:
            str =@"打印复印";
            break;
        case PTLifeService_BuyMealType:
            str =@"捎饭带饭";
            break;
        case PTLifeService_HotboomType:
            str =@"超市代购";
            break;
    }
    
    return str;
}

#pragma mark - 获取生活服务列表
static NSString * const kPT_Interface_URI_LifeServiceList= @"/app/service/list";
-(void)performGetLifeServiceListWithType:(PTLifeServiceType)type
                            universityId:(NSString *)universityId
                                    page:(NSInteger)page
                                     num:(NSInteger)num
                              Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setValue:[NSNumber numberWithInteger:type] forKey:@"type"];
    [dict setValue:universityId forKey:@"universityId"];
    [dict setValue:[NSNumber numberWithInteger:page] forKey:@"page"];
    [dict setValue:[NSNumber numberWithInteger:num] forKey:@"num"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_LifeServiceList Method:@"GET" Header:nil Parameters:dict ResultClass:[LifeServiceListModel class] Completion:completion];

}

#pragma mark - 获取服务详情内容
static NSString *const kPT_Interface_URI_LifeServiceListDetails= @"/app/service/detail";
-(void)performGetLifeServiceListDetailsWithServiceUUID:(NSString *)serviceUUID
                                              userUUID:(NSString *)userUUID
                                            Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setValue:serviceUUID forKey:@"uuid"];
    [dict setValue:userUUID forKey:@"userUUID"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_LifeServiceListDetails Method:@"GET" Header:nil Parameters:dict ResultClass:[LifeServiceListDetailModel class] Completion:completion];
}

#pragma mark - 我的发布列表
static NSString *const kPT_Interface_URI_LifeServiceMyReleaseList= @"/app/service/mine";
-(void)performGetMyReleaseServiceListWithUserUUID:(NSString *)userUUID
                                             page:(NSInteger)page
                                              num:(NSInteger)num
                                           status:(PTLifeServiceStatus)status
                                       Completion:(PTRESTfulCompletionHandler)completion{
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setValue:userUUID forKey:@"userUUID"];
    [dict setValue:[NSNumber numberWithInteger:status] forKey:@"status"];
    [dict setValue:[NSNumber numberWithInteger:page] forKey:@"page"];
    [dict setValue:[NSNumber numberWithInteger:num] forKey:@"num"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_LifeServiceMyReleaseList Method:@"GET" Header:nil Parameters:dict ResultClass:[LifeServiceMyListModel class] Completion:completion];
}

#pragma mark - 发布我的需求
static NSString *const kPT_Interface_URI_ReleaseOrder= @"/app/service/create";
static NSString *const kPT_Interface_URI_ResendReleaseOrder= @"/app/service/resend";

-(void)performPostReleaseOrderWithType:(PTLifeServiceType)type
                            expressCat:(nullable NSString *)expressCat
                           purchaseCat:(nullable NSString *)purchaseCat
                              userUUID:(nonnull const NSString *)userUUID
                             startTime:(nonnull const NSString *)startTime
                               endTime:(nonnull const NSString *)endTime
                           userAddress:(nonnull const NSString *)userAddress
                                reward:(NSInteger)reward
                       destinationName:(nullable NSString *)destinationName
                    destinationAddress:(nonnull const NSString *)destinationAddress
                            accessCode:(nullable NSString *)accessCode
                                copies:(nullable NSString *)copies
                                remark:(nullable NSString *)remark
                          universityId:(nonnull const NSString *)universityId
                              userName:(nullable NSString *)userName
                             userPhone:(nullable NSString *)userPhone
                           serviceUUID:(nullable NSString *)serviceUUID
                            Completion:(PTRESTfulCompletionHandler)completion
{
    
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
    [dict setValue:[NSNumber numberWithInteger:type] forKey:@"type"];
    [dict setValue:expressCat forKey:@"expressCat"];
    [dict setValue:purchaseCat forKey:@"purchaseCat"];
    [dict setValue:userUUID forKey:@"userUUID"];
    [dict setValue:startTime forKey:@"startTime"];
    [dict setValue:endTime forKey:@"endTime"];
    [dict setValue:userAddress forKey:@"userAddress"];
    [dict setValue:[NSNumber numberWithInteger:reward] forKey:@"reward"];
    [dict setValue:destinationName forKey:@"destinationName"];
    [dict setValue:destinationAddress forKey:@"destinationAddress"];
    [dict setValue:accessCode forKey:@"accessCode"];
    [dict setValue:copies forKey:@"copies"];
    [dict setValue:remark forKey:@"remark"];
    [dict setValue:universityId forKey:@"universityId"];
    [dict setValue:userName forKey:@"userName"];
    [dict setValue:userPhone forKey:@"userPhone"];
    
    if (serviceUUID!=nil && serviceUUID.length>0) {
        [dict setValue:serviceUUID forKey:@"uuid"];
        
        NSMutableDictionary * par =[[NSMutableDictionary alloc]init];
        [par setValue:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
        
        [self executeRESTfulTaskWithURI:kPT_Interface_URI_ResendReleaseOrder Method:@"POST" Header:nil Parameters:par ResultClass:[PTMJsonResult class] Completion:completion];
    }
    else
    {
        NSMutableDictionary * par =[[NSMutableDictionary alloc]init];
        [par setValue:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
        
        [self executeRESTfulTaskWithURI:kPT_Interface_URI_ReleaseOrder Method:@"POST" Header:nil Parameters:par ResultClass:[PTMJsonResult class] Completion:completion];
    }
}

#pragma mark - 取消发布
static NSString *const kPT_Interface_URI_CancelReleaseOrder= @"/app/service/cancel";

-(void)performPostCancelMyReleaseOrderWithServiceUUID:(NSString *)serviceUUID
                                           Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
    [dict setValue:serviceUUID forKey:@"uuid"];
    
    NSMutableDictionary * par =[[NSMutableDictionary alloc]init];
    [par setValue:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_CancelReleaseOrder Method:@"POST" Header:nil Parameters:par ResultClass:[PTMJsonResult class] Completion:completion];
}

#pragma mark - 删除发布
static NSString *const kPT_Interface_URI_DeleteReleaseOrder= @"/app/service/delete";
-(void)performPostDeleteMyReleaseOrderWithServiceUUID:(NSString *)serviceUUID
                                           Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
    [dict setValue:serviceUUID forKey:@"uuid"];
    
    NSMutableDictionary * par =[[NSMutableDictionary alloc]init];
    [par setValue:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_DeleteReleaseOrder Method:@"POST" Header:nil Parameters:par ResultClass:[PTMJsonResult class] Completion:completion];
}

#pragma mark - 举报用户
static NSString *const kPT_Interface_URI_ReportUser= @"/app/service/report";
-(void)performPostReportUserWithUserName:(NSString *)userName
                            receiverUUID:(NSString *)receiverUUID
                             serviceUUID:(NSString *)serviceUUID
                                    type:(PTLifeServiceType)type
                             missionUUID:(NSString *)missionUUID
                              Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
    [dict setValue:userName forKey:@"userName"];
    [dict setValue:receiverUUID forKey:@"receiverUUID"];
    [dict setValue:serviceUUID forKey:@"serviceUUID"];
    [dict setValue:missionUUID forKey:@"missionUUID"];
    [dict setValue:[self getServiceTypeName:type] forKey:@"type"];
    
    NSMutableDictionary * par = [[NSMutableDictionary alloc]init];
    [par setValue:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_ReportUser Method:@"POST" Header:nil Parameters:par ResultClass:[PTMJsonResult class] Completion:completion];
    
}

#pragma mark - 我要承接
static NSString *const kPT_Interface_URI_PickOrder= @"/app/service/pick";
-(void)performPostAcceptOrdersWithUserUUID:(NSString *)userUUID
                          serviceOwnerUUID:(NSString *)serviceOwnerUUID
                               serviceUUID:(NSString *)serviceUUID
                                      type:(PTLifeServiceType)type
                                Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
    [dict setValue:userUUID forKey:@"userUUID"];
    [dict setValue:serviceOwnerUUID forKey:@"serviceOwnerUUID"];
    [dict setValue:serviceUUID forKey:@"serviceUUID"];
    [dict setValue:[self getServiceTypeName:type] forKey:@"type"];
    
    NSMutableDictionary * par = [[NSMutableDictionary alloc]init];
    [par setValue:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_PickOrder Method:@"POST" Header:nil Parameters:par ResultClass:[PTMJsonResult class] Completion:completion];
}

#pragma mark - 发布者确认完成
static NSString *const kPT_Interface_URI_ConfirmFinish= @"/app/service/finish";
-(void)performPostConfirmFinishOrderWithUserName:(NSString *)userName
                                    receiverUUID:(NSString *)receiverUUID
                                     serviceUUID:(NSString *)serviceUUID
                                            type:(PTLifeServiceType)type
                                     missionUUID:(NSString *)missionUUID
                                      Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
    [dict setValue:userName forKey:@"userName"];
    [dict setValue:receiverUUID forKey:@"receiverUUID"];
    [dict setValue:serviceUUID forKey:@"serviceUUID"];
    [dict setValue:[self getServiceTypeName:type] forKey:@"type"];
    [dict setValue:missionUUID forKey:@"missionUUID"];
    
    NSMutableDictionary * par =[[NSMutableDictionary alloc]init];
    [par setValue:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_ConfirmFinish Method:@"POST" Header:nil Parameters:par ResultClass:[PTMJsonResult class] Completion:completion];
}

#pragma mark - 发布者 评价
static NSString *const kPT_Interface_URI_PublisherEvaluate= @"/app/service/evaluate";
-(void)performPostPublisherEvaluateWithUserName:(NSString *)userName
                                   receiverUUID:(NSString *)receiverUUID
                                    serviceUUID:(NSString *)serviceUUID
                                    missionUUID:(NSString *)missionUUID
                                           type:(PTLifeServiceType)type
                                         rating:(double)rating
                                     Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
    [dict setValue:userName forKey:@"userName"];
    [dict setValue:receiverUUID forKey:@"receiverUUID"];
    [dict setValue:serviceUUID forKey:@"serviceUUID"];
    [dict setValue:missionUUID forKey:@"missionUUID"];
    [dict setValue:[self getServiceTypeName:type] forKey:@"type"];
    [dict setValue:[NSNumber numberWithDouble:rating] forKey:@"rating"];
    
    NSMutableDictionary * par =[[NSMutableDictionary alloc]init];
    [par setValue:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_PublisherEvaluate Method:@"POST" Header:nil Parameters:par ResultClass:[PTMJsonResult class] Completion:completion];
}

#pragma mark - 我的兼职列表
static NSString *const kPT_Interface_URI_MyMissions = @"/app/service/missions";
-(void)performGetMyMissionsWithStatus:(PTLifeServiceMissionStatus)status
                             userUUID:(NSString *)userUUID
                                 page:(NSInteger)page
                                  num:(NSInteger)num
                           Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
    [dict setValue:[NSNumber numberWithInteger:status] forKey:@"status"];
    [dict setValue:userUUID forKey:@"userUUID"];
    [dict setValue:[NSNumber numberWithInteger:page] forKey:@"page"];
    [dict setValue:[NSNumber numberWithInteger:num] forKey:@"num"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_MyMissions Method:@"GET" Header:nil Parameters:dict ResultClass:[LifeServiceMyMissionsModel class] Completion:completion];
}

#pragma mark - 我的兼职完成之后删除
static NSString *const kPT_Interface_URI_MissionDelete = @"/app/service/mission/delete";
-(void)performPostMissionDeleteWithUUID:(NSString *)missionUUID
                             Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
    [dict setValue:missionUUID forKey:@"missionUUID"];
    
    NSMutableDictionary * par =[[NSMutableDictionary alloc]init];
    [par setValue:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_MissionDelete Method:@"POST" Header:nil Parameters:par ResultClass:[PTMJsonResult class] Completion:completion];
}

#pragma mark - 承接服务的完成
static NSString * const kPT_Interface_URI_MissionFinish = @"/app/service/mission/finish";
-(void)performPostMissionFinishWithUserName:(NSString *)userName
                           serviceOwnerUUID:(NSString *)serviceOwnerUUID
                                serviceUUID:(NSString *)serviceUUID
                                       type:(PTLifeServiceType)type
                                missionUUID:(NSString *)missionUUID
                                 Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
    [dict setValue:userName forKey:@"userName"];
    [dict setValue:serviceOwnerUUID forKey:@"serviceOwnerUUID"];
    [dict setValue:serviceUUID forKey:@"serviceUUID"];
    [dict setValue:[self getServiceTypeName:type] forKey:@"type"];
    [dict setValue:missionUUID forKey:@"missionUUID"];
    
    NSMutableDictionary * par =[[NSMutableDictionary alloc]init];
    [par setValue:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_MissionFinish Method:@"POST" Header:nil Parameters:par ResultClass:[PTMJsonResult class] Completion:completion];
}

#pragma mark - 我的兼职 查询详情
static NSString * const kPT_Interface_URI_MissionDetail = @"/app/service/missionDetail";
-(void)performGetMyMissionDetailWithUUID:(NSString *)uuid
                              Completion:(PTRESTfulCompletionHandler)completion
{
    NSMutableDictionary * dict =[[NSMutableDictionary alloc]init];
    [dict setValue:uuid forKey:@"uuid"];
    
    [self executeRESTfulTaskWithURI:kPT_Interface_URI_MissionDetail Method:@"GET" Header:nil Parameters:dict ResultClass:[LifeServiceMissionDetailModel class] Completion:completion];
}


@end
